<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="医生姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="认证状态">
              <a-select v-model="queryParam.certificationStatus" placeholder="请选择认证状态">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option value="0">待认证</a-select-option>
                <a-select-option value="1">认证中</a-select-option>
                <a-select-option value="2">已认证</a-select-option>
                <a-select-option value="3">认证失败</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('医生表')">导出</a-button>
      <a-button type="primary" icon="add" @click="addDoctor">新增医生</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <span style="float:right;">
          <a @click="loadData()"><a-icon type="sync" />刷新</a>
        </span>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <div
          slot="expandedRowRender"
          slot-scope="record"
          style="margin: 0">
          <a-row
            :gutter="24"
            :style="{ marginBottom: '12px' }">
            <a-col :span="12" v-for="(role, index) in record.permissions" :key="index" :style="{ marginBottom: '12px' }">
              <a-col :lg="4" :md="24">
                <span>{{ role.permissionName }}：</span>
              </a-col>
              <a-col :lg="20" :md="24" v-if="role.actionEntitySet.length > 0">
                <a-tag color="cyan" v-for="(action, k) in role.actionEntitySet" :key="k">{{ action.describe }}</a-tag>
              </a-col>
              <a-col :span="20" v-else>-</a-col>
            </a-col>
          </a-row>
        </div>

        <span slot="but" slot-scope="text, record">
            <a-dropdown>
             <span v-if="record.isDisplay == 1"></span>
               <span v-else>
                   <a-button  @click="addButWeb(record,$event)" type="primary">隐藏</a-button>
               </span>
           </a-dropdown>
             <a-dropdown >
             <span v-if="record.isDisplay == 2"></span>
               <span v-else>
                       <a-button  @click="addBut(record,$event)"  type="primary">显示</a-button>
               </span>
           </a-dropdown>
        </span>
        <template slot="text" slot-scope="text,record">
              <span  v-if="text" style="color:blue;">
                    <span>{{text}} %</span>
              </span>
          <span v-else="!text" style="color:#ff0000;"></span>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
           <a @click="handleDoctorForm(record)">编辑</a>
           <a-divider type="vertical" />
           <a @click="handleDoctorList(record)">详情</a>
           <a-divider type="vertical" />
           <a @click="handleDoctorSP(record)">视频问诊设置</a>
           <a-divider type="vertical" />
           <a @click="handleDoctorData(record)">分成比例</a>
           <a-divider type="vertical" />
           <a @click="handleDoctorRegister(record)">号源录入</a>
        </span>

      </a-table>
    </div>

    <add-doctor-form-modal ref="AddDoctorFormModal"></add-doctor-form-modal>
    <doctor-data-modal ref="DoctorDataModal"></doctor-data-modal>
    <doctor-register-modal ref="DoctorRegisterModal"></doctor-register-modal>
    <doctor-form-modal ref="DoctorFormModal"></doctor-form-modal>
    <doctor-list-modal ref="doctorListModal"></doctor-list-modal>
    <doctor-test-modal ref="doctorModal" @ok="submitOk"></doctor-test-modal>
    <doctor-modal ref="modalForm" @ok="modalFormOk"></doctor-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DoctorModal from './DoctorModal'
  import { getAction, getRoleList, getServiceList, postAction, putAction } from '@api/manage'
  import DoctorTestModal from './modules/DoctorTestModal'
  import DoctorRegisterModal from './modules/DoctorRegisterModal'
  import DoctorListModal from './modules/DoctorListModal'
  import DoctorFormModal from './modules/DoctorFormModal'
  import DoctorGoobModal from '@/views/doctor/modules/DoctorGoobModal'
  import DoctorIndexModal from '@/views/doctor/modules/DoctorIndexModal'
  import AddDoctorFormModal from './modules/AddDoctorFormModal'
  export default {
    name: 'DoctorList',

    inject: ['reload'],
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      DoctorModal,
      DoctorTestModal,
      DoctorListModal,
      DoctorFormModal,
      DoctorRegisterModal,
      AddDoctorFormModal
      // DoctorGoobModal,
      // DoctorIndexModal

    },
    data () {
      return {
        description: '医生表管理页面',
        modalVisible:false,

        doctorId:'',
        form: null,

        // 表头
        columns: [
          {
            title:'医生id',
            align:"center",
            dataIndex: 'id'
          },
          {
            title:'国医大师',
            align:"center",
            dataIndex: 'master',
            customRender:function (res) {
              var status = "";
              if(res == 0){
                status = "非大师";
              }else{
                status = "大师";
              }
              return status;
            }
          },
          {
            title:'医生名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'医生职称',
            align:"center",
            dataIndex: 'title'
          },
          {
            title:'认证状态',
            align:"center",
            dataIndex: 'certificationStatus',
            customRender:function (res) {
              var status = "";
              if(res == 0){
                status = "待认证";
              }else if(res == 1){
                status = "认证中";
              }else if(res == 2){
                status = "已认证";
              }else{
                status = "认证失败";
              }
              return status;
            }
          },
          // {
          //   title:'分成比例',
          //   align:"center",
          //   dataIndex: 'share',
          //   scopedSlots: { customRender: 'text' },
          // },
          {
            title:'医生显示',
            align:"center",
            scopedSlots: { customRender: 'but' },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:'147px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/doctor/doctor/list",
          display:"/doctor/doctor/display",
          delete: "/doctor/doctor/delete",
          deleteBatch: "/doctor/doctor/deleteBatch",
          exportXlsUrl: "/doctor/doctor/exportXls",
          importExcelUrl: "doctor/doctor/importExcel",
        },
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){},
      //医生详情
      doctorDetail(e){
        let id = e.id;
        this.$router.push(`/doctorDetail/${id}`)
      },

      addButWeb(e,event){
        let param = { };
        param.display = 1
        param.id = e.id

        event.currentTarget.innerHTML="隐藏";

        putAction(this.url.display,param).then(res=>{

          if(res.success){
            this.$message.success(res.message)
            this.reload()
          }else{
            this.$message.warning(res.message)
          }
        })
      },
      addBut(e,event){
        let param = { };
        param.display = 2
        param.id = e.id
        event.currentTarget.innerHTML="显示";
        putAction(this.url.display,param).then(res=>{
          if(res.success){
            this.$message.success(res.message)
            this.reload()
          }else{
            this.$message.warning(res.message)
          }
        })
      },
       //新增医生
      addDoctor(){
        this.$refs.AddDoctorFormModal.viewShow();
      },
      //详情
      handleDoctorList(record){
        this.$refs.doctorListModal.showDoctor(record);
      },

      //分成比例
      handleDoctorData(record){
        this.$refs.doctorModal.open(record);
        this.modalMisible = true;
      },

      //挂号管理
      handleDoctorRegister(record){
        this.$refs.DoctorRegisterModal.viewShow(record);
        this.modalMisible = true;
      },
      //挂号管理
      handleDoctorSP(record){
        this.$refs.DoctorRegisterModal.toMakeAppointmentList(record);
        this.modalMisible = true;
      },
      //编辑
      handleDoctorForm(record){
        this.$refs.DoctorFormModal.showDoctor(record);
      },
      handleDoctorIndex(record){
        this.$refs.DoctorIndexModal.showDoctor(record);
      },
    }
  }
</script>
<style>
  .j-table-force-nowrap .ant-table-thead .ant-table-expand-icon-th{
    /* display:none !important */
  }
  
  .ant-table-scroll .ant-table-fixed .ant-table-tbody .ant-table-row-expand-icon-cell .ant-table-row-expand-icon.ant-table-row-collapsed{ 
    display:none !important
  }
  
  .ant-modal-body{padding:0}
  /*@import '~@assets/less/common.less';*/
</style>